/*
 * 版权所有 (c) 2022-2099 TBIT。保留所有权利
 */

package com.tbit.config.HutoolHttp;

import cn.hutool.http.GlobalInterceptor;
import com.tbit.common.constant.CommonConstant;
import com.tbit.common.utils.TraceUtil;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 *  Hutool工具包http 全局拦截器配置
 *
 * <p>
 * 1、步骤1 <br> todo
 * 2、步骤2 <br> todo
 * 3、步骤3 todo
 * </p>
 *
 * @author <a href="mailto:zhang.zhiliang@tbit.com.cn">Zhang ZhiLiang</a>
 * @version 1.0 todo
 * @see <a href="http://adsl1.tbit.com.cn:21490/pages/viewpage.action?pageId=82182491">订单号规范</a> todo
 * @since 2024/5/14
 */
@Configuration
public class HutoolHttpConfig {

    /**
     * 使用Hutool工具包中的Http客户端发起http请求时设置traceId请求头
     */
    public HutoolHttpConfig(){
        GlobalInterceptor.INSTANCE.addRequestInterceptor(httpRequest -> {
            Map<String,String> headMap = new HashMap<>();
            headMap.put(CommonConstant.TRACE_ID, TraceUtil.getTraceIdByLocal());
            httpRequest.addHeaders(headMap);
        });
    }
}
